package guoanmaker.operator.business.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.InRoundPhone;

import guoanmaker.operator.business.model.OperatorPromotionNew;
import guoanmaker.operator.business.service.OperatorPromotionNewServiceInface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.OPERATOR_PROMOTION_NEW)
public class OperatorPromotionNewController {
	@Autowired
	private OperatorPromotionNewServiceInface operatorPromotionNewServiceInface;
	@ApiOperation(value = "保存运营推广", notes = "新增/修改运营推广")
    @PostMapping(value = "savePromotionNew")
    public AjaxJson savePromotionNew(@RequestBody InRoundPhone inRoundPhone) {
		AjaxJson ajaxJson=new AjaxJson();
    	try{
    		OperatorPromotionNew[] operatorPromotionNews=inRoundPhone.getOperatorPromotionNews();
    		operatorPromotionNewServiceInface.delectAllBycitycode(inRoundPhone.getCityId());
	    	for(OperatorPromotionNew promot:operatorPromotionNews){
	    		/*if(apphead.getId()!=null&&!apphead.getId().equals("")){
	    		operatorHeadlineServiceInterface.deleteHeadlineById(apphead.getId());}*/
	    		promot.setCreateDate(new Date());
	    		promot.setCitycode(inRoundPhone.getCityId());
	    		
	    		operatorPromotionNewServiceInface.saveOperatorPromotionNew(promot);
	    	}
	    	ajaxJson.setSuccess(true).setStatus(200).setData(null);
    	}catch(Exception e){
    		e.printStackTrace();
    		ajaxJson.setSuccess(true).setStatus(250).setData(null);
    	}
        return ajaxJson;
    }
	
	
	@ApiOperation(value = "查找所有运营推广", notes = "查找所有运营推广")
    @PostMapping(value = "getAllOperatorPromotionNewList")
  
    public AjaxJson getAllOperatorPromotionNewList(String citycode) {
		AjaxJson ajaxJson=new AjaxJson();
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorPromotionNewServiceInface.selectOperatorPromotionNewList(citycode));
    }
}
